module func_vec_mod; 
use vec_mod;
implicit none;
logical, save :: FUNC_VEC_MOD_TRACE_NEW = .TRUE.;
logical, save :: FUNC_VEC_MOD_TRACE_IF = .TRUE.;
logical, save :: FUNC_VEC_MOD_TRACE_ENTRY = .FALSE.;
!logical, save :: VEC_MOD_TRACE_ENTRY = .TRUE.;
integer, save :: NEW_FUNC_COUNT = 0;

type FUNC_VEC_T
  real(R14), dimension(:), pointer :: x, y, drv, drv2; 
end type

contains 

function new_func(xvec_p) result(self_p);  
  implicit none;  
  type(FUNC_VEC_T), pointer :: self_p;      
  real(R14), dimension(:), pointer :: xvec_p;
  integer :: status;
  call dbg_info("-->new_func()", FUNC_VEC_MOD_TRACE_ENTRY);
  allocate(self_p, STAT=status);
  self_p%x => xvec_p;
  self_p%y = new_vec_from(xvec_p);
  NULLIFY(self_p%drv, self_p%drv2)
  NEW_FUNC_COUNT = NEW_FUNC_COUNT + 1;
  call dbg_int("NEW_FUNC_COUNT=", NEW_FUNC_COUNT, FUNC_VEC_MOD_TRACE_NEW);
  return;
end function

subroutine del_func(self_p);  implicit none;  
  type(FUNC_VEC_T), pointer :: self_p      
  call dbg_info("-->del_func()", FUNC_VEC_MOD_TRACE_ENTRY);
  call dbg_bool("ASSOCIATED(self_p)=", ASSOCIATED(self_p), FUNC_VEC_MOD_TRACE_IF);
  if (ASSOCIATED(self_p)) then
    call del_vec(self_p%x);
    call del_vec(self_p%y);
    call del_vec(self_p%drv);
    call del_vec(self_p%drv2);
    DEALLOCATE(self_p);
    NEW_FUNC_COUNT = NEW_FUNC_COUNT - 1;
  end if     
  return;
end subroutine

end module 